home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™94 / Talks & Papers / Michael D. Crawford↵ / Word Services SDK 1.0.5 / Writeswell Jr. Source / MyHandlers.c < prev    next >
Text File  |  1992-11-12  |  3KB  |  112 lines

  1. /* MyHandlers.c
  2.  * Handle apple events for the SW IAC TestBed app
  3.  * ©1992 Working Software, Inc.
  4.  * This source code is copyrighted.  Permission is granted to use the Word Services
  5.  * portion of the Writeswell Jr. source code in your own programs, but you 
  6.  * may not distribute the Writeswell Jr. word-processor code as a 
  7.  * commercial product.  If you modify the code, please do not call it 
  8.  * Writeswell Jr. (or Writeswell.)  This will ensure that people understand the 
  9.  * program and don’t have to deal with a number of different versions with 
  10.  * who-knows-what going on in the code.
  11.  * 
  12.  * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
  13.  * 10 Sep 91 Mike Crawford
  14.  */
  15.  
  16. #include <AppleEvents.h>
  17. #include "MyHandlers.h"
  18. #include "TBConstants.h"
  19. #include "TBGlobals.h"
  20. #include "MyFiles.h"
  21. #include "Gripe.h"
  22.  
  23. pascal OSErr MyOAPPHandler( AppleEvent *theAppleEventPtr, AppleEvent *replyEventPtr, long refCon )
  24. {
  25.     return MakeNewWindow();
  26. }
  27.  
  28. pascal OSErr MyODocHandler( AppleEvent *theAppleEventPtr, AppleEvent *replyEventPtr, long refCon )
  29. {
  30.     AEDescList     docList;
  31.     long        itemsInList;
  32.     OSErr        err;
  33.     Str255        scratchStr;
  34.     FSSpec        myFSS;
  35.     AEKeyword    keywd;
  36.     Size        actualSize;
  37.     DescType    returnedType;
  38.     
  39.     if ( gDocWindow ){
  40.         return noErr;            /* Won't open more windows, but it's not an error, really */
  41.     }
  42.     
  43.     if ( err = AEGetParamDesc( theAppleEventPtr,
  44.                         keyDirectObject,
  45.                         typeAEList,
  46.                         &docList ) ){
  47.         Gripe( "\pGetParamDesc failed" );
  48.         return err;
  49.     }
  50.     
  51.     if ( err = AECountItems( &docList, &itemsInList ) ){
  52.         Gripe( "\pCountItems failed" );
  53.         return err;
  54.     }
  55.     
  56.     if ( itemsInList < 1 ){
  57.         Gripe( (StringPtr)"\pFewer than one file was specified" );
  58.         return errAEParamMissed;
  59.     }
  60.     
  61.     if ( itemsInList > 1 ){
  62.         /* This isn't really a problem... alert user and continue */
  63.         Gripe( (StringPtr)"\pWriteswell Jr. can only open one file" );
  64.     }
  65.         
  66.     if ( err = AEGetNthPtr( &docList,
  67.                             1,
  68.                             (DescType)typeFSS,
  69.                             &keywd,
  70.                             &returnedType,
  71.                             (Ptr)&myFSS,
  72.                             (Size)sizeof( myFSS ),
  73.                             &actualSize ) ){
  74.         Gripe( "\pGetNthPtr failed" );
  75.         return err;
  76.     }
  77.  
  78.     if ( err = MyOpenSpecFile( &myFSS ) ){
  79.         Gripe( "\pMyOpenFile failed" );
  80.         return err;
  81.     }
  82.     
  83.     return noErr;
  84. }
  85.  
  86. pascal OSErr MyPDocHandler( AppleEvent *theAppleEventPtr, AppleEvent *replyEventPtr, long refCon )
  87. {
  88.     OSErr err;
  89.     
  90.     err = MyODocHandler( theAppleEventPtr, replyEventPtr, refCon );
  91.     
  92.     if ( !err )
  93.         gPrintRequested = true;
  94.  
  95.     return err;
  96. }
  97.  
  98. pascal OSErr MyQuitHandler( AppleEvent *theAppleEventPtr, AppleEvent *replyEventPtr, long refCon )
  99. {
  100.     gQuitRequested = true;
  101.         
  102.     return noErr;
  103. }
  104.  
  105. pascal OSErr MyAnswerHandler( AppleEvent *theAppleEventPtr,
  106.                             AppleEvent *replyEventPtr,
  107.                             long refCon )
  108. {    
  109.     return noErr;
  110. }
  111.  
  112.